package com.relytosoft.mizar.media.display.api.pojo.dto;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.relytosoft.dubhe.common.core.utils.BeanCopyUtils;
import com.relytosoft.mizar.media.display.api.entity.ViewDetail;
import com.relytosoft.mizar.media.display.api.entity.ViewForm;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;

/**
 * 视图资源数据传输类
 *
 * @author hj
 * @version 1.0
 * @date 2022/4/25 14:54
 * @ClassName ViewFormDto
 */
@ApiModel("视图资源添加数据传输类")
public class ViewFormDto implements Serializable {

    private static final long serialVersionUID = 5307170400280398706L;
    /**
     * 主键
     */
    @ApiModelProperty(value = "主键ID")
    private Integer id;

    /**
     * 名称
     */
    @ApiModelProperty(value = "名称", required = true)
    @NotBlank(message = "名称不能为空")
    private String name;

    /**
     * 父ID
     */
    @ApiModelProperty(value = "父ID", required = true)
    @NotNull(message = "父ID不能为空")
    private Integer parentId;

    /**
     * 类型;1公有视图   2私有视图
     */
    @ApiModelProperty(value = "类型;1公有视图   2私有视图", required = true)
    @NotNull(message = "类型不能为空")
    private Integer type;

    /**
     * 视图类型;1视图组  2视图
     */
    @ApiModelProperty(value = "视图类型;1视图组  2视图", required = true)
    @NotNull(message = "视图类型不能为空")
    private Integer viewType;

    /**
     * 视图布局
     */
    @ApiModelProperty(value = "视图布局")
    private Integer layout;

    /**
     * 备注
     */
    @ApiModelProperty(value = "备注")
    private String remark;

    /**
     * 排序
     */
    @ApiModelProperty(value = "排序")
    private Integer index;


    /**
     * 拥有人
     */
    @ApiModelProperty(value = "拥有人")
    private Integer ownerId;

    @ApiModelProperty("视图明细列表")
    private List<ViewDetailDto> viewDetails;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getViewType() {
        return viewType;
    }

    public void setViewType(Integer viewType) {
        this.viewType = viewType;
    }

    public Integer getLayout() {
        return layout;
    }

    public void setLayout(Integer layout) {
        this.layout = layout;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public Integer getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(Integer ownerId) {
        this.ownerId = ownerId;
    }

    public void setViewDetails(List<ViewDetailDto> viewDetails) {
        this.viewDetails = viewDetails;
    }

    public List<ViewDetailDto> getViewDetails() {
        return viewDetails;
    }

    public ViewForm build(){
        ViewForm viewForm = new ViewForm();
        BeanCopyUtils.copy(this,viewForm);
        viewForm.setSort(this.getIndex());
        //暂时用不上排序，默认为1
        viewForm.setSort(1);
        //状态设为1
        viewForm.setStatus(1);
        return viewForm;
    }

    public static ViewFormDto buildDto(ViewForm form){
        ViewFormDto viewFormDto = new ViewFormDto();
        BeanCopyUtils.copy(form,viewFormDto);
        viewFormDto.setIndex(form.getSort());
        return viewFormDto;
    }
}
